package com.bourne.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bourne.constant.NumConstant;
import com.bourne.enums.BizCodeEnum;
import com.bourne.mapper.BaseDictMapper;
import com.bourne.model.BaseDictDO;
import com.bourne.request.DictRequest;
import com.bourne.service.BaseDictService;
import com.bourne.util.JsonData;
import com.bourne.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @version 1.0
 * @ClassName BaseDictServiceImpl
 * @Description
 * @Author denny
 * @Date 2023/3/10 15:21
 */
@Service
public class BaseDictServiceImpl extends BaseCoreServiceImpl<BaseDictMapper, BaseDictDO> implements BaseDictService {


    @Autowired(required = false)
    private PageUtils<BaseDictDO> pageUtils;

    @Override
    public JsonData add(DictRequest dictRequest) {

        BaseDictDO baseDictDO = new BaseDictDO(dictRequest);
        int inRow = mapper.insert(baseDictDO);
        return inRow == NumConstant.ONE ? JsonData.buildSuccess() : JsonData.buildResult(BizCodeEnum.REQUEST_FAIL);
    }

    @Override
    public JsonData pageList(DictRequest dictRequest) {
        BaseDictDO baseDictDO = new BaseDictDO(dictRequest);
        Page<BaseDictDO> page = pageUtils.pageInfoInit();
        QueryWrapper<BaseDictDO> queryWrapper = this.getQueryWrapper(baseDictDO, BaseDictDO.class, true);
        Page<BaseDictDO> userDOPage = mapper.selectPage(page, queryWrapper);
        Map<String, Object> map = pageUtils.pageDataMap(userDOPage);
        return JsonData.buildSuccess(map);
    }
}
